Skip to content

fix(android): skip the tap-escape guard when the launcher owned the focus before - #5011

Merged
thymikee merged 1 commit into
callstack:mainfrom
imranbarbhuiya:fix/android-escape-check-foreground-before
Nov 23, 2026
Merged

thymikee merged 1 commit into
callstack:mainfrom
imranbarbhuiya:fix/android-escape-check-foreground-before

Conversation

@imranbarbhuiya

@imranbarbhuiya imranbarbhuiya commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The Android escape check failed a deliberate touch made while the session app was already in the background. After home, a longpress on a launcher icon opened the shortcut menu but returned COMMAND_FAILED … The tap likely escaped the app, so agents retried a gesture that had already worked.

The check is now skipped only when an escape surface (the launcher, Settings, System UI) owned the focus before the dispatch. The focus comes from the blocking-dialog readiness read that already runs before each touch, so there's no extra device call. A permission prompt, custom tab or sign-in activity in the app's flow, or a read that names no package, keeps the check. Messages now name the actual command.

Before / after

Pixel 9 AVD (Android 16): open <app>, home, snapshot -i, then a long-press on the app's launcher icon:

$ longpress @e12
base a4f2dcad0: COMMAND_FAILED: press @e12 left <app> and foregrounded com.google.android.apps.nexuslauncher. The tap likely escaped the app.
head 5aa044cce: Long pressed @e12 (907, 1986)
# on both, the next snapshot -i shows the shortcut menu (App info, Widgets)

Validation

  • Head 5aa044cce, check:affected --run --head, exactCommit: true. Format, lint, typecheck, layering, fallow, build and vitest-related pass. unit fails only on upload-http-deadline and committed-source-tree, which fail the same way on clean main on this macOS host. test:integration:provider passes when run directly (317/317).
  • The new daemon and observation tests fail at base, or against a skip on any other focused package.
  • A touch that really leaves the app, where the app owned the focus before, is still an error. That case is covered by tests only.

Proof this PR
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

View guided diff

…ocus before

The post-touch escape guard compared the foreground after the dispatch with the
session app and never looked at what was in front before it. A deliberate
longpress on the launcher after `home` therefore failed with "press ... left
<app> and foregrounded <launcher>", although the gesture ran.

The before-command blocking-dialog readiness read already learns the focused
window, from the helper focus call or the window dump. It now reports that
window's package on a clear read. The guard skips a touch dispatched while an
escape surface (launcher, Settings, System UI) already owned the focus. Other
packages in an app flow, such as a permission prompt or a custom tab, and a
read that names no package keep the guard. The guard's messages name the
actual command instead of "press".
@thymikee

Copy link
Copy Markdown
Member

Thanks for the fix. At 5aa044c this is ready: the guard now skips only when the launcher owned the focus before the tap, and the launcher-before test is the one that fails without the change.

Not blocking, and fine to take or leave: the retained route (app owns focus, a tap escapes, the guard still throws) has no live run at this head, so one run where pressing an in-app element opens Settings or the launcher and returns COMMAND_FAILED 'left and foregrounded ' would cover it; ANDROID_COMPONENT_PATTERN duplicates the package/Activity regex that parseAndroidResumedActivity still inlines, so one shared constant would do; the long JSDoc line and the "CONSERVATIVE:" comment in interaction-android-escape.ts could be wrapped and trimmed to the invariant, and the helper could reuse the existing observation type for its return; and the Trusted Web Activity and permission prompt tests also pass without the fix, so they pin retained behavior only.

The Smoke Tests failure looks unrelated: the Linux desktop job stopped in 'Install Linux desktop dependencies' because apt-get update timed out, before any repo code ran. The other Smoke Tests, Integration, Coverage and Lint jobs pass at this head, and Body rules passes. There are no conflicts. Re-running the Smoke Tests job should clear the last red check.

Not verified here: the Pixel 9 AVD transcript in the PR body, whether that run used the helper path or the dumpsys path for the focus read, and the tests locally; they were read, not run.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 23, 2026
@thymikee
thymikee merged commit 9dc37c5 into callstack:main Nov 23, 2026
14 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants